<?php
include("../config/connect.php");
include("../public/common.php");

$type = CheckUrlParamNoDie( "type" );
$userid = CheckUrlParamNoDie( "userid" );
if ($type == "" || $userid == "")
{
	echo "0";
	exit;
}

//
if ($type == "r")	// 推荐
{
	$result = mysql_query("select count(*) as tmp from gwt_tubi_guizhe where user_id=$userid and type='$type' and date(time)=date(now())");
	$row = mysql_fetch_assoc( $result );
	if ($row["tmp"] > 0)
	{
		echo "2";	// 已经有了
	}
	else
	{
		$addlevel = 5;
		mysql_query( "update user set level=level+$addlevel,tubi=tubi+$addlevel where id=$userid" );
		mysql_query( "insert into gwt_msg (touser,content) values ($userid,'您把购物兔推荐给好友获得了 5 个兔币。')" );
		mysql_query( "insert into gwt_tubi_guizhe (user_id,type) values ($userid,'$type')" );
		echo "1";			
	}
	
	exit;
}
else if ($type == "s")	// 晒单
{
	$itemid = CheckUrlParamNoDie( "itemid" );
	if ($itemid != "")
	{
		$result = mysql_query("select count(*) as tmp from gwt_tubi_guizhe where user_id=$userid and type='$type' and other='$itemid'");
		$row = mysql_fetch_assoc( $result );
		if ($row["tmp"] > 0)
		{
			echo "2";	// 已经有了
		}
		else
		{	
			$result = mysql_query("select count(*) as tmp from gwt_tubi_guizhe where user_id=$userid and type='$type' and date(time)=date(now())");
			$row = mysql_fetch_assoc( $result );
			if ($row["tmp"] >= 4)
			{
				echo "2";	// 已经有了
			}
			else
			{
				$addlevel = 5;
				mysql_query( "update user set level=level+$addlevel,tubi=tubi+$addlevel where id=$userid" );
				mysql_query( "insert into gwt_msg (touser,content) values ($userid,'您将商品分享到微博获得 5 兔币。')" );
				mysql_query( "insert into gwt_tubi_guizhe (user_id,type,other) values ($userid,'$type','$itemid')" );
				echo "1";			
			}
		}
	}
	else
	{
		echo "0";
	}
	
	exit;
}

?>